using System.Reflection;
using NUnit.Framework;
using Rhino.Mocks;

namespace ShadeTree.Binding.Tests
{
    [TestFixture]
    public class ChildScreenBinderTester
    {
        #region Setup/Teardown

        [SetUp]
        public void SetUp()
        {
            _mocks = new MockRepository();
            _innerBinder = _mocks.StrictMock<IScreenBinder>();

            PropertyInfo property = typeof (SomeTopic).GetProperty("Child");
            _childBinder = new ChildScreenBinder<ChildTopic>(_innerBinder, property);
        }

        #endregion

        private MockRepository _mocks;
        private IScreenBinder _innerBinder;
        private ChildScreenBinder<ChildTopic> _childBinder;

        [Test]
        public void ApplyChanges()
        {
            using (_mocks.Record())
            {
                Expect.Call(_innerBinder.ApplyChangesToModel()).Return(true);
            }

            using (_mocks.Playback())
            {
                _childBinder.ApplyChanges();
            }
        }

        [Test]
        public void Grab_the_child_property_on_bind_and_call_through_to_the_inner_binder()
        {
            var topic = new SomeTopic();
            topic.Child = new ChildTopic();

            using (_mocks.Record())
            {
                _innerBinder.BindToModel(topic.Child);
            }

            using (_mocks.Playback())
            {
                _childBinder.Bind(topic);
            }
        }

        [Test]
        public void Reset()
        {
            using (_mocks.Record())
            {
                _innerBinder.ResetToOriginalValues();
            }

            using (_mocks.Playback())
            {
                _childBinder.Reset();
            }
        }

        [Test]
        public void Update()
        {
            using (_mocks.Record())
            {
                _innerBinder.UpdateScreen();
            }

            using (_mocks.Playback())
            {
                _childBinder.Update();
            }
        }
    }

    public class SomeTopic
    {
        public ChildTopic Child { get; set; }
    }

    public class ChildTopic
    {
    }
}